home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / xlib / xlib06p2 / demo5.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-22  |  4.8 KB  |  153 lines

  1. /*************************************************************************
  2.  
  3. DEMO 5
  4.  
  5. Demonstrates Planar Bitmap Clipping Functions
  6.  
  7. Themie Gouthas
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <malloc.h>
  17. #include <dos.h>
  18. #include "xlib.h"
  19. #include "xpbitmap.h"
  20. #include "xpbmclip.h"
  21. #include "xrect.h"
  22. #include "xbmtools.h"
  23. #include "xline.h"
  24. #include "xtext.h"
  25. /* Macro to make pointer parameters model independent */
  26.  
  27. int i,j;
  28.  
  29. char turtle[] = {
  30.     20,30,
  31. /*  |      .       |       .      |       .      |      .       */
  32.     8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.     8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.     8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.     8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.     8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.     8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  38.     0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  39.     0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  40.     0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  41.     0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  42.     0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  43.     0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  44.     0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  45.     0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  46.     0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  47.     2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  48.     0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  49.     0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  50.     0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  51.     0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  52.     0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  53.     0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  54.     0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  55.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  56.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  57.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  58.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  59.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  60.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  61.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  62.     };
  63.  
  64.  
  65. char  *vbm;
  66.  
  67. void error(char * string){
  68.   x_text_mode();
  69.   printf("%s\n",string);
  70.   exit(0);
  71. }
  72.  
  73. typedef struct {
  74.   unsigned int  size;           /* valid only for the first header */
  75.   unsigned char ImageWidth;
  76.   unsigned char ImageHeight;
  77.   unsigned int  ImagePtr;
  78.   unsigned int  MaskPtr;
  79. } alignment_header;
  80.  
  81.  
  82. void main(){
  83.     int i,j,k,handle,size,comp_size;
  84.     char  *bm;
  85.  
  86.     alignment_header   * tempbuff;
  87.     x_set_mode(X_MODE_360x240,360);
  88.     ;NonVisual_Offs=16384;
  89.  
  90.     x_text_init();
  91.     x_set_font(FONT_8x15);
  92.     x_bgprintf(0,0,0,14,0," This is a demo of PBM clipping.");
  93.     getch();
  94.  
  95.     bm=(char *)malloc(20*30+2);
  96.     x_bm_to_pbm( turtle ,bm);
  97.  
  98.     x_set_cliprect(4,5,50,150);
  99.  
  100.     x_line(0,TopClip-1,320,TopClip-1,23,0);
  101.     x_line(0,BottomClip+1,320,BottomClip+1,23,0);
  102.     x_line((LeftClip<<2)-1,0,(LeftClip<<2)-1,200,23,0);
  103.     x_line((RightClip<<2)+4,0,(RightClip<<2)+4,200,23,0);
  104.  
  105.     for (k=0;k<8;k++) {
  106.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  107.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  108.         x_put_pbm(i+k+1,j,0,(BYTE *)bm);
  109.     }
  110.  
  111.     x_line(0,TopClip-1,320,TopClip-1,23,0);
  112.     x_line(0,BottomClip+1,320,BottomClip+1,23,0);
  113.     x_line((LeftClip<<2)-1,0,(LeftClip<<2)-1,200,23,0);
  114.     x_line((RightClip<<2)+4,0,(RightClip<<2)+4,200,23,0);
  115.  
  116.     x_rect_fill((LeftClip<<2),TopClip,(RightClip<<2)+3,BottomClip,0,0);
  117.  
  118.     x_bgprintf(0,BottomClip+4,0,14,0," Now the clipping...");
  119.     getch();
  120.  
  121.     for (k=0;k<8;k++){
  122.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  123.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  124.         x_put_pbm_clipxy(i+k+1,j,0,(BYTE *)bm);
  125.     }
  126.     for (k=0;k<8;k++){
  127.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  128.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  129.         x_put_pbm_clipxy(i+7+1,j+k,0,(BYTE *)bm);
  130.     }
  131.     for (k=7;k>=0;k--){
  132.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  133.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  134.         x_put_pbm_clipxy(i+k+1,j+7,0,(BYTE *)bm);
  135.     }
  136.     for (k=7;k>=0;k--){
  137.      for (j=1;j<ScrnPhysicalHeight;j+=30)
  138.       for (i=0;i<ScrnPhysicalPixelWidth-20;i+=20)
  139.         x_put_pbm_clipxy(i+1,j+k,0,(BYTE *)bm);
  140.     }
  141.  
  142.     getch();
  143.     x_text_mode();
  144.     printf("%d %d %d %d\n",LeftClip,TopClip,RightClip,BottomClip);
  145.  
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.